Practice Lab 7.1 – Business rules
Scenario
You are a Power Platform functional consultant and have been assigned to the Fabrikam project for the next stage of the project.
In this practice lab, you will be creating business rules to show and hide the lookup columns in the model-driven app form for the Resource table and to set the status of Milestone rows to completed when the percentage complete is 100%. You will also create a low-code plug-in to validate dates.
Exercise 1 – Create business rules
Task 1.1 – Create Resource business rules
-
Navigate to the Power Apps Maker portal
https://make.powerapps.com
-
Make sure you are in the Dev One environment.
-
Select Solutions.
-
Open the Fabrikam Environmental solution.
-
In the Objects pane on the left, expand Tables.
-
Select the Resource table.
-
Under Customizations, select Business rules.
-
Select the existing business rule, Set Resource Name, to open the business rule designer. Analyze how this business rule works. This business rule controls the visibility and requirement for the resource name based on the selection of resource type.
-
Close the Business rule designer.
-
Select Done.
-
Select + New business rule from the command bar.
-
In the Business rule designer, next to the New business rule name at the top of the screen, select the drop-down caret.
-
Enter
Resource Type Internal
for Business rule name. You can select on the drop-down caret again to collapse this section. -
In the Scope drop-down in the top-right of the Business rules designer, select All Forms.
-
Select the Condition tile in the canvas and in the Properties pane enter
Check Resource Type
for Display Name. -
In the Rules section, select Resource Type for Field, select Equals for Operator, select Value for Type, and select Internal for Value.
-
Select Apply.
-
Select the Components tab.
-
Drag the Set Visibility action and place it on the True side (on the right-hand side) of the condition.
-
Enter
Show User
for Display Name. -
In the Visibility section, select User and Yes.
-
Select Apply.
-
Drag another Set Visibility action from the Components tab and place it on the right-hand side of the Show User tile.
-
Enter
Hide Contact
for Display Name. In the Visibility section, select Contact and No. -
Select Apply.
-
Select + Add and select Add Set Business Required and then select the plus icon to the right of the Hide Contact tile.
-
Enter
User Required
for Display Name. In the Business Required section, select User and Business Required. -
Select Apply.
-
Select + Add and select Add Set Business Required and then select the plus icon to the right of the User Required tile.
-
Enter
Contact Not Required
for Display Name. In the Business Required section, select Contact and Not Business Required. -
The Business Rule (Text View) should read as follows:
IF Resource Type equals "Internal" THEN Show field User Hide field Contact Set User as Business Required Set Contact as Not Business Required
-
Select Save. You should see the message Validation successful.
-
Select Activate.
-
In the Process Activate Confirmation dialog, select Activate.
-
Select Save As.
-
Next to Copy of Resource Type Internal name at the top of the screen, select the drop-down caret.
-
Enter
Resource Type External
for Business rule name. Collapse the top section. -
Select the Check Resource Type tile.
-
In the Rules section, uncheck Internal and check External.
-
Select Apply.
-
Select the Show User tile.
-
Enter
Hide User
for Display Name. Select User, No in the Visibility section and select Apply. -
Select the Hide Contact tile.
-
Enter
Show Contact
for Display Name. Select Contact, Yes in the Visibility section and select Apply. -
Select the User Required tile.
-
Enter
User Not Required
for Display Name, select Not Business Required in the Business Required section and select Apply. -
Select the Contact Not Required tile.
-
Enter
Contact Required
for Display Name, select Business Required for Status and select Apply. -
The Business Rule (Text View) should read as follows:
IF Resource Type equals "External" THEN Hide field User Show field Contact Set User as Not Business Required Set Contact as Business Required
-
Select Save. You should see the message that Validation was successful.
-
Select Activate.
-
In the Process Activate Confirmation dialog, select Activate.
-
Close the business rule designer tab.
-
Select Done.
Task 1.2 – Create Milestone business rules
-
In the Objects pane on the left, select the Milestone table.
-
Under Customizations, select Business rules.
-
Select + New business rule.
-
Next to New business rule name at the top of the screen, select the drop-down caret.
-
Enter
Milestone Completed
for Business rule name. Collapse the top section. -
In the Scope drop-down in the top-right of the business rules designer, select Entity.
-
Select the Condition tile in the canvas and in the Properties pane, enter
Percentage Complete
for Display Name. -
In the Rules section, select Milestone Percentage Complete for Field, select Equals for Operator, select Value for Type, and enter
100
for Value. -
At the top of the Rules section, select + New to add Rule 2.
-
In the Rule 2 section, select Milestone Status for Field, select Does not equal for Operator, select Value for Type, and check Completed and Cancelled for Value.
-
Select AND for Rule Logic.
-
Select Apply.
-
The Condition Expression (Text View) should read as follows:
Milestone Percentage Complete equals 100 AND Milestone Status does not equal "Completed,Cancelled"
-
Select + Add and select Add Set Field Value and then select the plus icon to the right of the Condition tile.
-
Enter
Mark Complete
for Display Name. In the Field Value section, select Milestone Status for Field, select Value for Type, and select Completed for Value. -
Select Apply.
-
The Business Rule (Text View) should read as follows:
IF Milestone Percentage Complete equals 100 AND Milestone Status does not equal "Completed,Cancelled" THEN Set Milestone Status to "Completed"
-
Select Save. You should see the message that Validation was successful.
-
Select Activate.
-
In the Process Activate Confirmation dialog, select Activate.
-
Close the business rule designer tab.
-
Select Done.
Exercise 2 – Low code plug-in
Task 2.1 – Create a low-code plug-in
-
Navigate to the Power Apps Maker portal
https://make.powerapps.com
-
Make sure you are in the Dev One environment.
-
Select Apps.
-
Select All
-
Select the Dataverse Accelerator App and select Play.
-
Select + New plug-in and select Automated plug-in.
-
Enter
Project date validation
for Display name. -
Select contoso_project for Table.
-
Select Updated for Run this plug-in when the row is.
-
Expand Advanced options.
-
Select Pre-operation for When should this run.
-
Select Fabrikam Environmental for Solution.
-
Enter the following Expression.
If(NewRecord.'Scheduled Start' > NewRecord.'Scheduled End', Error({Kind: ErrorKind.Validation, Message: "The start date cannot be after the end date" }) );
-
Select Save.
Challenge (Optional)
Edit the Set Resource Name business rule on the Resource table to hide both lookup columns if resource type is not selected and set as not business required.